package com.ganinfo.common.date;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import com.xiaoleilu.hutool.date.DateUtil;

/**
 * @ClassName: DateMyxUtil
 * @Description: 时间相关工具类
 * @author: ruikanwang
 * @date: 2017年3月6日 下午4:02:42
 */
public class DateMyxUtil {
	/**
	 * @Title: getBeginEndWeed
	 * @Description: 获取一段时间内所有的开始时间结束时间(每周)
	 * @return: void
	 */
	@SuppressWarnings("deprecation")
	public static List<Date> getBeginEndWeed(Date startDay,
			Date endDay) {
		Calendar c_begin = new GregorianCalendar();
		Calendar c_end = new GregorianCalendar();
		//DateFormatSymbols dfs = new DateFormatSymbols();
		//String[] weeks = dfs.getWeekdays();
		c_begin.set(startDay.getYear(), startDay.getMonth() + 1,
				startDay.getDate()); // Calendar的月从0-11，所以4月是3.
		c_end.set(endDay.getYear(), endDay.getMonth() + 1, endDay.getDate()); // Calendar的月从0-11，所以5月是4.

		int count = 1;
		c_end.add(Calendar.DAY_OF_YEAR, 1); // 结束日期下滚一天是为了包含最后一天
        List<Date> dateList=new ArrayList<>();
        dateList.add(new Date(c_begin.getTime().getTime()));
		while (c_begin.before(c_end)) {
			System.out.println("第" + count + "周  日期："
					+ new Date(c_begin.getTime().getTime()));

			if (c_begin.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
				dateList.add(new Date(c_begin.getTime().getTime()));
				dateList.add(DateUtil.offsiteDay(new Date(c_begin.getTime().getTime()),1));
				count++;
			}
			c_begin.add(Calendar.DAY_OF_YEAR, 1);
		}
		return dateList;
	}
	
	
	@SuppressWarnings("deprecation")
	public static void main(String[] args) {
		List<Date> beginEndWeed = DateMyxUtil.getBeginEndWeed(new java.sql.Date(2017, 1, 20), new java.sql.Date(2017, 2, 20));
		System.out.println(beginEndWeed);
	}

}
